
function initLivePage()
{
	var timerEnabled = false;
	var timeOut = 1000*60*5;
	
	function showMessage(msg)
	{
		$('#current')[0].innerHTML = msg;
	}
	
	function check()
	{
		if(geo_position_js.init())
		{
			showMessage("Your browser is supported");
			$("#formUpdate").show();
		}
		else
		{
			showMessage("Functionality not available");
		}
	}
	
	function update()
	{
		geo_position_js.getCurrentPosition
		(
			show_position,
			function()
			{
				showMessage("Couldn't get location");
				if (timerEnabled) setTimeout(update, timeOut);
			},
			{enableHighAccuracy:true}
		);	
	}
	
	function show_position(res)
	{
		$.ajax({
			url: "/Add/",
			cache: false,
			type: "POST",
			data: {"longitude" : res.coords.longitude, "latitude" : res.coords.latitude},
			success: function(json)
			{
				showMessage("(" + res.coords.latitude + ", " + res.coords.longitude + ") at " + res.timestamp + " - OK");
				if (timerEnabled) setTimeout(update, timeOut);
			},
			error: function(arg)
			{
				showMessage("Could not send data to server");
			}
		});		
		
	}
	
	function startTimer()
	{
		timerEnabled = true;
		$("#btnStart").hide();
		$("#btnStop").show();
		$("#updateInterval")[0].disabled = true;
		update();
		timeOut = $("#updateInterval")[0].value*1000*60;
		setTimeout(update, timeOut);
	}
	
	function stopTimer()
	{
		timerEnabled = false;
		$("#btnStart").show();
		$("#btnStop").hide();
		$("#updateInterval")[0].disabled = false;
	}

	return {check : check, update : update, startTimer: startTimer, stopTimer: stopTimer};
}